<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="static/css/1bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/js/1jquery.min.js"></script>
<script src="static/js/1bootstrap.min.js"></script>
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>发邮件</title>
</head>
<body style="margin-top: 30px; margin-left: 200px; margin-right: 200px">

	<table>
		<div class="form-group">
			<label for="name">收件人</label>
			<select name="recname" class="form-control" id="selectname"></select>
		</div>
		<div class="form-group">
			<label for="name">标题</label>
			<input name="title" type="text" class="form-control" placeholder="输入标题">
		</div>
		<div class="form-group">
			<label for="name">内容</label>
			<textarea name="message" id="message" class="form-control" rows="20"></textarea>
		</div>
		<br>
		<input class="easyui-filebox" data-options="prompt:'添加文件',
			buttonText:'选择附件',multiple:true" id="images" name="images" style="width: 300px;" />
		<input type="button" onclick="send()" class="d-btn btn-blue" style="float: right; border: 0;"
			value="发&nbsp;&nbsp;&nbsp;&nbsp;送" />

	</table>

</body>

<script>
	var title = "";
	var message = "";
	var recname = "";
	function send() {
		var formData = new FormData();
		formData.append("title", $("input[name='title']").val());
		formData.append("recname", $("#selectname").find("option:selected").val());
		formData.append("message", $("#message").val());
		var images = document.getElementById("filebox_file_id_1").files;
		for(var i = 0;i < images.length;i++){
			formData.append('images', images[i]);
		}
		$.ajax({
			type : 'POST',
			url : "sendmail.do",
			cache : false,
			data : formData,
			processData : false,
			contentType : false,
			success : function(data) {
				if (data.success){
					$.messager.alert('提示', '发送成功', 'success');
					window.setInterval("location.reload()", 2000);
				}else{
					$.messager.alert('提示', '发送失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function getUserName() {
		$.ajax({
			type : "GET",
			url : "getAllUserName",
			datatype : "json",
			success : function(data) {
				var selectname = $("#selectname");
				if (data){
					$.each(data, function(i,userlist) {
						selectname.append("<option value="+ userlist.username +">" + userlist.name + "</option>");
					});
				}
			}
		});
	}
	getUserName();
</script>
</html>